package com.mayikt.thread;

/**
 * @ClassName Thread004
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class Thread004 extends Thread {
    private volatile boolean flag = true;

    @Override
    public void run() {

        while (flag) {

        }

    }

    public void stopThrad() {
        this.flag = false;
    }

    public static void main(String[] args) {
        Thread004 thread004 = new Thread004();
        thread004.start();
        try {
            Thread.sleep(3000);
        } catch (Exception e) {

        }
        thread004.stopThrad();
        // 不建议使用stopt停止线程，因为他底层使用强制停止线程 如果线程代码没有执行完毕的情况下则强制停止
    }
}
